package cn.dazhou.hellomqtt

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import com.hivemq.client.mqtt.MqttGlobalPublishFilter
import com.hivemq.client.mqtt.datatypes.MqttQos
import com.hivemq.client.mqtt.mqtt3.Mqtt3AsyncClient
import com.hivemq.client.mqtt.mqtt3.Mqtt3Client
import com.hivemq.client.mqtt.mqtt3.message.publish.Mqtt3Publish

class MainActivity : AppCompatActivity() {

    private val testTopic = "topic/hello"

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
    }

    fun connect(view: View) = Mqtt.connect()
    fun disconnect(view: View) = Mqtt.disconnect()
    fun subscribe(view: View) = Mqtt.subscribe(testTopic)
    fun unsubscribe(view: View) = Mqtt.unsubscribe(testTopic)
    fun publish(view: View) = Mqtt.publish("How are you?", testTopic)
    fun publishRetain(view: View) = Mqtt.publish("I'm a retain message!", testTopic, retain = true)
    fun clearRetain(view: View) = Mqtt.clearRetainMessage(testTopic)

}